{% extends "base.html" %}

{% block title %}账单管理 - 风之宿{% endblock %}

{% block content %}
<div class="container mx-auto px-4 py-8">
  <h1 class="text-3xl font-bold text-primary mb-8">账单管理</h1>

  <div class="bg-white rounded-lg shadow-md overflow-hidden">
    <div class="overflow-x-auto">
      <table class="min-w-full divide-y divide-gray-200">
        <thead class="bg-gray-50">
          <tr>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">用户</th>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">入住日期</th>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">退房日期</th>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">金额</th>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">状态</th>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">创建时间</th>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">支付时间</th>
            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">删除</th>
		  </tr>
        </thead>
        <tbody class="bg-white divide-y divide-gray-200">
          {% for bill in bills %}
          <tr>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ bill.username }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ bill.check_in }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ bill.check_out }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">¥{{ bill.amount }}</td>
            <td class="px-6 py-4 whitespace-nowrap">
              <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full
                {% if bill.status == 'paid' %}bg-green-100 text-green-800
                {% else %}bg-yellow-100 text-yellow-800{% endif %}">
                {{ bill.status }}
              </span>
            </td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ bill.created_at }}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
              {% if bill.paid_at %}{{ bill.paid_at }}{% else %}-{% endif %}
            </td>
        <!-- 推荐使用POST方法提交删除请求，更安全 -->
		<td>
			<form action="{{ url_for('admin.delete_bill', bill_id=bill.id) }}" method="post" onsubmit="return confirm('确定要删除该账单吗？');">
			  <button type="submit" class="text-red-600 hover:text-red-800">删除</button>
			</form>
		</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</div>
{% endblock %}